﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TrucTiepService;

namespace TrucTiep.Controllers
{
    public class TrucTiepController : Controller
    {
        //
        // GET: /TrucTiep/

        public ActionResult Index()
        {
            var extenssion = new TrucTiepService.TrucTiepService();
            var ListTrucTiep = extenssion.getlistTrucTiepAnhChuong();
            ViewBag.TrucTiep = ListTrucTiep;
            return View();
        }
        public ActionResult UpdateTrucTiepAnhChuong(int id = 0)
        {
            var extenssion = new TrucTiepService.TrucTiepService();
            var choose = extenssion.getTrucTiepAnhChuong(id);
            int? ID = 0;
            double? Commission = 0;
            if (choose != null)
            {
                ID = choose.ID;
                Commission = choose.Commission;
            }
            ViewBag.ID = ID;
            ViewBag.Commission = Commission;
            return View();
        }
        [HttpPost]
        public ActionResult UpdateTrucTiepAnhChuong(FormCollection fc)
        {
            var ad = fc["id"];
            if (ad.Contains(','))
                ad = ad.Replace(',', '.');
            int id = int.Parse(ad, CultureInfo.InvariantCulture);
            var cd = fc["Commission"];
            if (cd.Contains(','))
                cd = cd.Replace(',', '.');
            double Commission = double.Parse(cd, CultureInfo.InvariantCulture);
            var extenssion = new TrucTiepService.TrucTiepService();
            var choose = extenssion.getTrucTiepAnhChuong(id);
            if (choose != null)
            {
                choose.Commission = Commission;
                extenssion.UpdateTrucTiepAnhChuong(choose);
            }
            return RedirectToAction("Index", "TrucTiep");
        }
      
    }
}
